var scoreLabel = null;
// retrieve the score label
function getScoreLabel(){
	if (scoreLabel == null){
		scoreLabel = document.getElementById('toub-waves-vote-gadget_scoreLabel');
	}
	return scoreLabel;
}
// vote for this bind (with a positive or negative offset
function vote(scoreOffset) {
	var state = wave.getState();
	if (state != null){
		var score = parseInt(state.get('score', '0'));
		state.submitDelta( {
				'score' : score + scoreOffset
			});
	}
}

// called by wave when state is updated
function stateUpdated() {
	var state = wave.getState();
	if (state != null){
		var score = state.get('score')
		if (score == null) {
			// initial score
			score = "0"
		}
		if (getScoreLabel() != null){
			getScoreLabel().innerHTML = score;
		}
	}
}

// initialize the gadget
function init() {
	if (wave && wave.isInWaveContainer()) {
		// register state callback method
		wave.setStateCallback(stateUpdated);
	}
}
// register init method
gadgets.util.registerOnLoadHandler(init);